<%@ page language="java" contentType="text/html; charset=UTF-8"  pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<!DOCTYPE html>
<html lang="zh">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>首页</title>
    <c:set value="${pageContext.request.contextPath}" var="path" scope="page"/>
	<link rel="stylesheet" href="${path}/static/style/index.css">
	<script src="${path}/static/script/jQuery 3.5.1.min.js"></script>
</head>

<body>
    <div id="main">
        <header>
            <nav class="top-bar">
                <div class="welcom">欢迎，${user.getUsername()}</div>
                <div class="mine">我的 ···
                    <ul class="mine-ul">
                        <li class="mine-item"><a href="/Discovery/list">我的发布</a></li>
                        <li class="mine-item"><a href="/Discovery/add">发布创作</a></li>
                        <li class="mine-item"><a href="/Discovery/logout">退出登录</a></li>
                    </ul>
                </div>
            </nav>
        </header>
        <main>
        	<c:forEach var="item" items="${list}">
	            <div class="discovery-content">
	                <div class="user">
	                    <div class="user-avatar"></div>
	                    <div class="user-name">${item.user.username}</div>
	                </div>
	                <div class="content">
	                    <div class="-title">
	                        ${item.title}
	                    </div>
	                    <img class="-img" src="/imagesdir/${item.imgname}" alt="">
	                    <div class="-date">
	                    	<fmt:formatDate value="${item.date}" pattern="yyyy-MM-dd" />
	                    </div>
	                    <c:if test="${user.getId() == item.userid}">
		                    <div class="-action">
		                        <a href="del?id=${item.id}" onclick="return confirm('你确定要删除吗?');" class="btn">删除</a>
		                    </div>
		                </c:if>
	                </div>
	            </div>
	        </c:forEach>
        </main>
    </div>
    <script>
        $('.mine').on('click', function () {
            $(this).children('ul').slideToggle(200);
        })
    </script>
</body>

</html>